<template>
    <div class="main_box"  style="padding:10px">
      <div class="add_wrap">
        <div class="tit">
          <h2>{{"设备信息"}}</h2>
          <el-button type="success" plain size="small" icon="fa fa-mail-forward" @click="returnList">返回</el-button>
        </div>
        <el-form :model="dataForm" ref="dataForm" label-width="200px" :rules="roleRules">
            <el-row>
                <el-form-item label="名称：">
                    <span>{{messageInfo.equipName}}</span>
                </el-form-item>
                <el-form-item label="编号：">
                  <span>{{messageInfo.equipCode}}</span>
                </el-form-item>
                <el-form-item label="类型：">
                  <span  v-if="messageInfo.equipType==1">呼叫器</span>
                  <span  v-if="messageInfo.equipType==2">接收器</span>
                  <span  v-if="messageInfo.equipType==3">安全设备</span>
                </el-form-item>
                <el-form-item label="地址：">
                  <span>{{messageInfo.address}}</span>
                </el-form-item>
                <el-form-item label="联系人：">
                  <span>{{messageInfo.phones&&messageInfo.phones.length>0?messageInfo.phones[0].name:""}}</span>
                </el-form-item>
                <el-form-item label="联系电话：">
                  <span>{{messageInfo.phones&&messageInfo.phones.length>0?messageInfo.phones[0].phone:""}}</span>
                </el-form-item>
            </el-row>

          <div class="tit">
             <h2>{{"处理内容"}}</h2>
          </div>
          <el-row>
            <el-form-item label="消息类型：">
              <span v-if="messageInfo.remindType==1">万能键</span>
              <span v-if="messageInfo.remindType==2">设备离线异常</span>
              <span v-if="messageInfo.remindType==3">设备报警异常</span>
            </el-form-item>
            <el-form-item label="消息提醒内容：">
              <span>{{messageInfo.remindContent}}</span>
            </el-form-item>
            <el-form-item label="处理结果：" prop="disposeResult">
              <el-input type="textarea" v-model="dataForm.disposeResult"></el-input>
            </el-form-item>
            <el-form-item label="备注：" prop="remark">
              <el-input type="textarea" v-model="dataForm.remark"></el-input>
            </el-form-item>
            <el-form-item label="是否电联客户：" prop="contactFlag">
                <el-radio v-model="dataForm.contactFlag" :label="1">是</el-radio>
                <el-radio v-model="dataForm.contactFlag" :label="0">否</el-radio>
            </el-form-item>
          </el-row>

          <el-row style="text-align: center;">
            <el-button plain type="primary" @click="sureClick(0)">保 存</el-button>
            <el-button plain type="success" @click="sureClick(1)" v-if="messageInfo.equipType==1">新增订单</el-button>
            <el-button plain type="danger"  @click="resetMessage">退出重置消息状态</el-button>
          </el-row>
        </el-form>

      </div>
     </div>
    </template>

    <script>
    import * as message from "@/constants/message";
    import ServerMessageApi from "@/api/message/serverMessage";
    export default{
      data(){
          return {
            userRole:"",
            detailRole:"",
            dataForm:{
              remindId:"", //消息Id
              disposeResult:"",
              remark:"",
              contactFlag:1,
            },
            messageInfo:{},
            loadingIns:false,
            roleRules: {
              disposeResult:[
                {required:true,message:"请填写结果",trigger:"blur"}
              ],
            },
            roleList :[],
          }
        },
      mounted(){
        this.init()
      },
      methods: {
        init(){
           // 获取用户的角色信息
          // this.userRole = getStorage(USER_INFO).userRole
          // this.detailRole = getStorage(USER_INFO).detailRole
          this.getEquipInfo()
        },
        keydown(e) {
          if (e.keyCode == 32) {
            e.returnValue = false;
          }
        },
        // 获取设备信息
        getEquipInfo(){
          this.dataForm.remindId = this.$route.query.id
          ServerMessageApi.serverRemindInfo({id:this.dataForm.remindId}).then(res=>{
            this.messageInfo = res.data
          })
        },
        // 重置消息状态
        resetMessage(){
          this.$confirm("确认重置消息状态？", message.TITLE_PROMPT, {
            confirmButtonText:"确认",
            cancelButtonText:"取消"
          })
          .then(() => {
            ServerMessageApi.resetMessage({id:this.dataForm.remindId,state:1}).then(res=>{
              this.$store.dispatch('delView', this.$route);
              this.$router.push({path: '/message/serverMessageManagement'});
            })
          });


        },
        sureClick(flag) {
          this.toOrderPage = flag
          this.$refs.dataForm.validate(valid => {
            if (valid) {
              this.$confirm(this.toOrderPage?"是否保存并去新增订单？":message.MSG_CONFIRM_SAVE_ALTER, message.TITLE_PROMPT, {})
                .then(() => {
                  this.editData()
              });
            }
          })
        },
        editData() {
          let params = {
            remindId:this.dataForm.remindId,
            disposeResult:this.dataForm.disposeResult,
            remark:this.dataForm.remark,
            contactFlag:this.dataForm.contactFlag,
          };
          ServerMessageApi.resolveMessage(params).then(res=>{
            // 是否去订单页面
            if(this.toOrderPage){
              this.$router.push({path: '/order/orderAdd',query:{id:this.dataForm.remindId}});
            }else{
              this.$router.push({path: '/message/serverMessageManagement'});
            }

          })
        },

        // 返回并把消息状态从处理中改为待处理
        returnList(){
            this.$store.dispatch('delView', this.$route);
            this.$router.push({path: '/message/serverMessageManagement'});
        }
      },

    }
    </script>
<style lang="scss" scoped>
@import "@/assets/css/views/add.scss";
</style>
